- Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathMapsDemo.java
74 lines (47 loc) Β· 1.64 KB
/
MapsDemo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
packagecollections;
importjava.util.HashMap;
importjava.util.LinkedHashMap;
importjava.util.TreeMap;
publicclassMapsDemo {
publicstaticvoidmain(String[] args) {
System.out.println("HashMap demo\n");
HashMap<Integer, String> map = newHashMap<>();
map.put(5, "testing");
map.put(1, "nirmal");
map.put(2, "rabindra");
map.put(3, "om");
System.out.println(map.entrySet());
System.out.println("size: " + map.size());
System.out.println(map);
System.out.println(map.containsKey(2));
System.out.println(map.containsValue("OM"));
System.out.println(map.containsValue("om"));
System.out.println(map.keySet());
System.out.println(map.values());
System.out.println(map.remove(3));
System.out.println(map);
System.out.println("\nLinkedHashMap demo\n");
LinkedHashMap<Integer, String> lmap = newLinkedHashMap<>();
lmap.put(1, "nirmal");
lmap.put(2, "rabindra");
lmap.put(3, "om");
System.out.println(lmap);
System.out.println(lmap.entrySet());
System.out.println(lmap.keySet());
System.out.println(lmap.values());
System.out.println("\nTreeMap demo\n");
TreeMap<String, String> tmap = newTreeMap<>();
tmap.put("aab", "Hello");
tmap.put("aaa", "First expected");
tmap.put("aad", "last expected");
System.out.println(tmap);
System.out.println(tmap.entrySet());
System.out.println(tmap.lastEntry());
System.out.println(tmap.ceilingKey("aab"));
System.out.println(tmap.ceilingKey("aar"));
// System.out.println(tmap.pollFirstEntry());
System.out.println(tmap);
System.out.println(tmap.subMap("aaa", false, "aar", false));
System.out.println(tmap.tailMap("aab", false));
}
}